import { reqBookingRoom, reqRoomByCondition } from "@/api";
import route from "@/route";
import { Message ,  MessageBox} from "element-ui";
export default({
    namespaced:true,
    actions:{
        async getRoomListByCondition(context,value){
            let result=await reqRoomByCondition(value);
            if(result.code==='200'){
                context.commit('getRoomListByCondition',result.other)
            }else{
                Message({
                    message: '警告!'+'['+result.code+']'+'['+result.message+']',
                    type: 'warning'
                })
                return;
            }
        },
        async bookingRoom(context,value){
            let result=await reqBookingRoom(value);
            if(result.code==='200'){
                context.commit('bookingRoom')
            }else{
                Message({
                    message: '警告!'+'['+result.code+']'+'['+result.message+']',
                    type: 'warning'
                })
                return;
            }
        }
    },
    mutations:{
        getRoomListByCondition(state,value){
            state.roomList=value
        },
        bookingRoom(state,value){
            MessageBox.confirm('预约成功, 是否查看预约记录?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(() => {
                   //路由跳转至统计组件
                    route.push({
                        name:'BookingRecord'
                    })
              }).catch(() => {
                this.$message({
                  type: 'info',
                  message: '已取消'
                });
                location.reload();          
              });
            // 待办：confirm窗口判断是否查看预约记录
            //点击确认跳转至预约记录组件
            //点击取消本页面刷新重新进入组件
            // let result=confirm("预约成功,是否查看预约记录？")
            // if(result){
               
            // }else{
                
            // }
        }
    },
    state:{
        roomList:[]
    },
    getters:{

    }
})